package com.ruoyi.hr.controller.hr.changemanage.attributechange;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.CompanysService;
import com.ruoyi.hr.service.DepartmentsService;
import com.ruoyi.hr.service.JobsService;
import com.ruoyi.hr.service.changemanage.attributechange.AttributeChangeService;
import com.ruoyi.hr.service.changemanage.depchange.DepChangeService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 员工属性变更登记
 * @date 2020/4/18
 */
@Controller
@RequestMapping("/changeManage/AttributeChange")
public class AttributeChangeController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    AttributeChangeService attributeChange;

    @Autowired
    CompanysService companysService;


    private String prefix = "hr/changemanage/attributechange";

    @GetMapping()
    public String AttributeChange() {
        return prefix + "/attributeChange";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(attributeChange.list(map, authority));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        //公司
        mmap.put("companys", companysService.findAllCompanys(null));
        mmap.put("AttributeChangeData", attributeChange.getAttributeChangeData(id));
        return prefix + "/editAttributeChange";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map){
        return toAjax(attributeChange.edit(map));
    }

    @GetMapping("/getWorkCity")
    public String getWorkCity() {
        return prefix + "/getWorkCity";
    }

    @GetMapping("/getNewReportTo")
    public String getReportTo(String type, ModelMap mmap) {
        mmap.put("type", type);
        return prefix + "/getNewReportTo";
    }

    @GetMapping("/add")
    public String add(){
        return prefix + "/addAttributeChangeEmp";
    }

    @RequestMapping("/findEmp")
    @ResponseBody
    public TableDataInfo findEmp(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(attributeChange.findEmp(map, authority));
    }

    /**
     * 执行添加员工存储过程
     */
    @PostMapping("/addEmp")
    @ResponseBody
    public BaseResult addEmp(String allEid) {
        return attributeChange.addEmp(allEid);
    }

    /**
     * 数据确认,取消确认,执行
     */
    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String procedure) {
        return attributeChange.procedure(allId, procedure);
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(attributeChange.remove(ids));
    }

    @GetMapping("/history")
    public String history() {
        return prefix + "/history";
    }

    @RequestMapping("/historyList")
    @ResponseBody
    public TableDataInfo historyList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(attributeChange.historyList(map, authority));
    }

}
